package mephisto.rest.resources;

import mephisto.services.impl.Utils;

import org.restlet.Context;
import org.restlet.data.Form;
import org.restlet.data.MediaType;
import org.restlet.data.Request;
import org.restlet.data.Response;
import org.restlet.resource.Representation;
import org.restlet.resource.Resource;
import org.restlet.resource.ResourceException;
import org.restlet.resource.StringRepresentation;
import org.restlet.resource.Variant;

public class ApplicationVersionResource extends Resource {

    protected String resource = null;
    
    public ApplicationVersionResource(Context context, Request request, Response response) {
        super(context, request, response);
        resource  = (String) request.getAttributes().get("resource");
        if (resource == null)
            resource = "";
        getVariants().add(new Variant(MediaType.TEXT_PLAIN));
    }

    public Representation represent(Variant variant) throws ResourceException {
        if (variant.getMediaType().equals(MediaType.TEXT_PLAIN)) {

            Utils su = new Utils();
            try {
                Form parameters = new Form();
                parameters.add("id","arkub");
                parameters.add("password","kubar");
                parameters.add("oreference", getRequest().getOriginalRef().toString());
                //String out = su.createPage("version", parameters);
                return new StringRepresentation("Version", MediaType.TEXT_HTML);  
            } catch (Exception e) {

                e.printStackTrace();
                return new StringRepresentation(e.getMessage(), MediaType.TEXT_HTML);  
            }
            
              
            
        }
        
        String s = "Mephisto service. Protocol version: 0.1";
        return new StringRepresentation(s);
        
        

        
    }

    
}
